Skip to content

feat: add PprofLabeling wrapper labeling each request via runtime/pprof.Do - #46

Open
qm012 wants to merge 2 commits into
mainfrom
pprof
Open

feat: add PprofLabeling wrapper labeling each request via runtime/pprof.Do#46
qm012 wants to merge 2 commits into
mainfrom
pprof

Conversation

@qm012

@qm012 qm012 commented Aug 22, 2026

Copy link
Copy Markdown
Owner

Adds a PprofLabeling wrapper that serves every request inside runtime/pprof.Do,
so CPU profile samples and goroutine tracebacks can be attributed to their route.

  • Labels default to the matched r.Pattern; a Labels function can add pairs like a trace ID
  • Registered via Use, not bundled in Default()
  • Adds tests and a runnable example under examples/pprof-labeling

Usage

pl := &sim.PprofLabeling{Labels: func(r *http.Request) []string {
    return []string{"pattern", r.Pattern, "trace_id", traceID(r.Context())}
}}

app := sim.NewApp()
app.Use(traceID.Handler, pl.Handler, new(sim.Recovery).Handler)

Labels default to the matched route pattern when Labels is nil. Filter samples while profiling:

go tool pprof -tagfocus='pattern=GET /users/{id}' http://host/debug/pprof/profile

@qm012 qm012 self-assigned this Aug 22, 2026
@qm012 qm012 added documentation Improvements or additions to documentation enhancement New feature or request labels Aug 22, 2026
qm012 added 2 commits August 23, 2026 15:17
Signed-off-by: qm012 <67568757+qm012@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/qm012/sim 89.74% (+0.32%) 👍
github.com/qm012/sim/examples/pprof-labeling 0.00% (ø)

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/qm012/sim/examples/pprof-labeling/main.go 0.00% (ø) 0 0 0
github.com/qm012/sim/examples/pprof-labeling/traceid_log_handler.go 0.00% (ø) 0 0 0
github.com/qm012/sim/pprof_labeling.go 100.00% (+100.00%) 7 (+7) 7 (+7) 0 🌟

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/qm012/sim/pprof_labeling_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant